import { request } from './base'
export interface Question {
	id: string
	content: string | null
	answer: string | null
	tag: string | null
	option1: string | null
	option2: string | null
	option3: string | null
	option4: string | null
	questionType?: number
	isCorrect?: boolean
}

export interface AnswerInfo {
	examId?:  string|null
	questionId?:  string|null 
	userAnswer?:  string|null
	userScore?: number | null
	[property: string]: any
}
// 获取所有题目
export async function getAllQuestions(
	pageNum: number,
	pageSize: number
): Promise<any> {
	const response = await request.get('/leveQuestionBank/selectAll', {
		params: {
			pageNum,
			pageSize
		}
	})
	return response.data.data.data
}

// 提交用户作答信息
export async function createQuestionSelection(
	requestData: AnswerInfo
): Promise<any> {
	const response = await request.post(
		'/leveQuestionSelection/create',
		requestData
	)
	return response.data
}

//获取作答记录
export async function getQuestionSelection(examId:string,questionId:string):Promise<any>{
    const response = await request.get('//leveQuestionSelection/getByPrimaryKey',{
        params:{
            examId,
            questionId
        }
    })
    return response.data
}

//添加题目
export async function createLeveQuestionBank(requestData:Question):Promise<any>{
  const response = await request.post('/leveQuestionBank/create',{...requestData})
  return response.data
}

//删除题目
export async function deleteLeveQuestionBank(id:string):Promise<any>{
    const response = await request.delete('/leveQuestionBank/delete',{params:{id}})
    return response.data
}

//更新题目
export async function updateLeveQuestionBankById(id:string,requestData:Question):Promise<any>{
	const response = await request.put('/leveQuestionBank/update/',{...requestData},{params:{id}})
	return response.data
}

//根据id获取对应题目
export async function getLeveQuestionBankById(id:string):Promise<any>{
    const response = await request.get('/leveQuestionBank/getById',{params:{id}})
    return response.data
}